package cn.edu.imau.zy.examination.service.impl;

import java.util.List;

import cn.edu.imau.zy.common.utils.DateUtils;
import cn.edu.imau.zy.common.utils.poi.ExcelUtil;
import cn.edu.imau.zy.examination.domain.ElRepo;
import cn.edu.imau.zy.examination.mapper.ElRepoMapper;
import cn.edu.imau.zy.examination.service.IElRepoService;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import cn.edu.imau.zy.common.core.text.Convert;

/**
 * 题库Service业务层处理
 *
 * @author xsc
 * @date 2021-05-07
 */
@Service
public class ElRepoServiceImpl extends ServiceImpl<ElRepoMapper, ElRepo> implements IElRepoService {
    @Override
    public List<ElRepo> queryList(ElRepo elRepo) {
        LambdaQueryWrapper<ElRepo> lqw = Wrappers.lambdaQuery();
        if (elRepo.getTitle() != null) {
            lqw.like(ElRepo::getTitle, elRepo.getTitle());
        }
        return this.list(lqw);
    }

    /**
     * 单表多条件查询
     */
    @Override
    public ElRepo queryElRepo(ElRepo elRepo) {
        QueryWrapper<ElRepo> wrapper = new QueryWrapper<>();
        wrapper.eq("title", elRepo.getTitle());
        ElRepo el = baseMapper.selectOne(wrapper);
        return el;
    }

    @Override
    public boolean updateByCode(ElRepo elRepo) {
        LambdaQueryWrapper<ElRepo> lqw = Wrappers.lambdaQuery();
        lqw.eq(ElRepo::getCode, elRepo.getCode());
        int update = baseMapper.update(elRepo, lqw);
        if (update > 0 ){
            return true;
        }
        return false;
    }

    @Override
    public List<ElRepo> getQuNameList() {
        return baseMapper.selectList(null);
    }


}
